package libra;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Component;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;

/**
 * 通过代码的形式向NaocsConfig配置中心推送配置文件
 * @author libra
 */
//@Component
public class NacosConfigSender  {
	static final String nacosRemoteAddress = "localhost:8848";
	static final String groupId = "DEFAULT_GROUP";
	@PostConstruct
	public void after() throws Exception {
		// 通过代码的形式向NaocsConfig配置中心推送配置文件
        final String dataId = "nacos-sentinel-provider-flow.sender.txt";
        final String rule = "[\n"
            + "  {\n"
            + "    \"resource\": \"TestResource\",\n"
            + "    \"controlBehavior\": 0,\n"
            + "    \"count\": 5.0,\n"
            + "    \"grade\": 1,\n"
            + "    \"limitApp\": \"default\",\n"
            + "    \"strategy\": 0\n"
            + "  }\n"
            + "]";
        ConfigService configService = NacosFactory.createConfigService(nacosRemoteAddress);
        boolean publishConfig = configService.publishConfig(dataId, groupId, rule);
        System.out.println( "publishConfig->"+publishConfig );
	}
}
